package ioc

import (
	"gitee.com/flycash/ai-gateway-demo/internal/grpc/interceptor/rate_limiter"
	"github.com/gotomicro/ego/core/econf"
)

func InitRateLimiter() *rate_limiter.TokenBucket{
	type rateLimitConfig struct {
		Capacity int64 `json:"capacity"`
		Rate    int64 `json:"rate"`
	}
	var conf rateLimitConfig
	err := econf.UnmarshalKey("rateLimiter", &conf)
	if err != nil {
		panic(err)
	}
	return rate_limiter.NewTokenBucket(conf.Capacity, conf.Rate)
}
